package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppBanner;
import com.vf.admin.miaodong.entity.AppCashWithdrawal;
import com.vf.admin.miaodong.entity.AppUser;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * 提现
 */
@Repository
public class AfterCashWithdrawalDao extends BaseDao<AppCashWithdrawal> {

    /**
     * 查询列表
     */
    public List<AppCashWithdrawal> findList(Map<String,Object> paraMap, SplitPageBean splitPage) {
        List<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT a.* FROM app_cashwithdrawal a where 1=1 ");
        if (StringEx.isNotNull(paraMap.get("phone"))) {
            sbStr.append(" and a.phone like ? ");
            paramList.add("%" + paraMap.get("phone") + "%");
        }
        if(StringEx.isNotNull(paraMap.get("nick"))){
            sbStr.append(" and a.nick = ? ");
            paramList.add(paraMap.get("nick"));
        }
        if(StringEx.isNotNull(paraMap.get("status"))){
            sbStr.append(" and a.status = ? ");
            paramList.add(paraMap.get("status"));
        }
        if(StringEx.isNotNull(paraMap.get("statusNotIn"))){
            sbStr.append(" and a.status != ? ");
            paramList.add(paraMap.get("statusNotIn"));
        }
        if (!StringEx.isNull(paraMap.get("startDate"))) {
            sbStr.append(" and a.createtime>=? ");
            paramList.add(paraMap.get("startDate"));
        }
        if (!StringEx.isNull(paraMap.get("endDate"))) {
            sbStr.append(" and a.createtime<=? ");
            paramList.add(paraMap.get("endDate"));
        }
        sbStr.append(" order by a.createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppCashWithdrawal.class, splitPage);
    }


    /**
     * 详情
     */
    public AppCashWithdrawal get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_cashwithdrawal where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppCashWithdrawal.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppCashWithdrawal haoYou) {
        if (haoYou!=null && haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id==null || id <= 0) {
            return;
        }
        String sql = "delete  from app_cashwithdrawal where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 根据用户id和提现状态获取提现记录
     */
    public AppCashWithdrawal getOneByStatus(Integer userid) {
        if (StringEx.isNullOrLing(userid)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_cashwithdrawal userid = ? and status = 1");
        paramList.add(userid);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppCashWithdrawal.class);
    }

}
